<?php

if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 友情链接模型类
 */
class Link_model extends CI_Model
{

	/**
	 * 根据id获取一条信息
	 */
	public function get($linkid)
	{
		$query = $this->db->get_where('common_link', array('linkid' => $linkid));
		$row = $query->row_array();
		return $row;
	}

	/**
	 * 获取全部信息（根据条件）
	 */
	public function get_many_by($key, $value = NULL)
	{
		!is_array($key) && $key = array($key => $value);

		$query = $this->db->where($key)->order_by('vieworder ASC')->get('common_link');
		$result = $query->result_array();
		return $result;
	}

	/**
	 * 插入
	 */
	public function insert($data)
	{
		$this->db->insert('common_link', $data);
		return $this->db->insert_id();
	}

	/**
	 * 更新
	 */
	public function update($data)
	{
		$id = 0;

		if ($data['linkid'])
		{
			$this->db->where('linkid', $data['linkid']);
			$this->db->update('common_link', $data);

			$id = $data['linkid'];
		}

		return $id;
	}

	/**
	 * 批量更新
	 */
	public function update_batch($data)
	{
		if (is_array($data) && count($data > 0))
		{
			$this->db->update_batch('common_link', $data, 'linkid');
		}
	}

	/**
	 * 删除
	 */
	public function delete($linkid)
	{
		$this->db->where('linkid', $linkid);
		$this->db->delete('common_link');
	}
}

/* End of file link_model.php */
/* Location: ./application/models/link_model.php */
